# %% env
import os

# os.environ["OPENAI_API_KEY"] = ''
# os.environ["OPENAI_API_BASE"] = ''

# %% use env
from dotenv import load_dotenv

load_dotenv()
# %% import model
'''
LangChain has built a Wrapper around OpenAl APls,using which we can get access to all the services OpenAl provides.
The code snippet below imports a specific class called 'ChatOpenAl'(Wrapper around OpenAl large language models)from the 'chat_models'module of the
langchain'library.
'''
from langchain_community.chat_models import ChatOpenAI

# %%
'''
The code snippet below imports HumanMessage,SystemMessage and
 AlMessage from the 'schema'module of the langchain'library.
'''

from langchain.schema import HumanMessage, SystemMessage, AIMessage

# %% create model
'''
Initialize the ChatOpenAl object and
We'll set temperature=.7 to maximise randomness and make outputs creative.  temperature添加随机性
The parameter model_name is provided with the value "gpt-3.5-turbo"which is a specific version or variant of a language model for chat
'''

chat = ChatOpenAI(
    temperature=0.7,
    # base_url=" ",
    # api_key=" ",
    # 报错307 就换一个模型试试
    model_name="gpt-3.5-turbo",  # OK
)

# %% chat with
'''
Chats with the Chat-GPT model 'gpt-3.5-turbo'are typically structured like so:
System:You are a helpful assistant.
User:Hi Al,how are you today?
Assistant:I'm great thank you.How can I help you?
User:I'd like to understand string theory.
Assistant:The final "Assistant:"without a response is what would prompt the model to continue the comversation.In the official
'''

result = chat(
    [
        # 设定
        SystemMessage(content="You are a sarcastic AI assistant"),
        # 用户提问
        HumanMessage(content="Please answer in 30 words:How can I learn driving a car")
    ]
)

print(result.content)
# %% more detail chat
'''
In the below scenario
We are asking the model to behave in a specific way
And passing our question
And also passing on more context so that it can elaborate more on that specific topic
This model gives us a better way to have conversation kind of opportunity with the model,which can be used to build chat bots.
'''

ourConversation = chat(
    [
        SystemMessage(content="You are a 3 years old girl who answers very cutely and in a funny way"),
        HumanMessage(content="How can I learn driving a car"),
        AIMessage(content="I can't drive yet! But I have a driver,my dad..."),
        HumanMessage(content="Can you teach me driving?")
    ]
)
print(ourConversation.content)
